package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.OrderSettingListService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 预约业务
 * */
@RestController
@RequestMapping("/orderSettingList")
public class OrderSettingListController {
    @Reference
    private OrderSettingListService orderSettingListService;

    /**
     * 添加预约业务管理
     * member       预约基本信息
     * setmealIds    预约下面所有的套餐
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody Member member, Integer[] setmealIds) {

        try {
            //调用service的接口，将数据传输过去
            orderSettingListService.add(member, setmealIds);
            return new Result(true, MessageConstant.ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERSETTING_FAIL);
        }
    }

    /**
     * 分页
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
       return  orderSettingListService.findPage(queryPageBean);
    }

    /**
     * 确认预约后，修改预约状态
     * @param id
     * @param orderDate
     * @param setmealId
     * @return
     */
    @RequestMapping("/update.do")
    public Result update(Integer id , String orderDate, Integer setmealId){
        try {
            orderSettingListService.update(id,orderDate,setmealId);
            return new Result(true,MessageConstant.ORDER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.ORDER_FULL);
        }
    }
    /**
     *  取消预约
     * @param id
     * @param orderDate
     * @param setmealId
     * @return
     */
    @RequestMapping("/delete")
    public Result delete(Integer id , String orderDate, Integer setmealId) {
        try {
            orderSettingListService.delete(id,orderDate,setmealId);
            return new Result(true,MessageConstant.CANCEL_ORDER_SUCCESS);
        }catch (RuntimeException e){
          return new Result(false, MessageConstant.CANNOT_CANCEL_ORDER);
        } catch (Exception e){
        e.printStackTrace();
            return new Result(false,MessageConstant.CANCEL_ORDER_FAIL);
        }
    }

}
